package com.ruoyi.fly.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.fly.domain.PcUser;
import com.ruoyi.fly.domain.vo.PcUserSearchVo;
import com.ruoyi.fly.domain.vo.UserUpdateVo;
import com.ruoyi.fly.mapper.PcUserMapper;
import com.ruoyi.fly.service.PcUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PcUserServiceImpl implements PcUserService {

    @Autowired
    private PcUserMapper userMapper;

    /**
     * 根据主键查询用户
     *
     * @param id 用户主键
     * @return
     */
    @Override
    public PcUser selectCAuthUserById(String id) {
        return userMapper.selectCAuthUserById(id);
    }

    /**
     * 查询用户列表
     *
     * @param pcUser 用户
     * @return
     */
    @Override
    public List<PcUser> selectCAuthUserList(PcUserSearchVo pcUser) {
        return userMapper.selectCAuthUserList(pcUser);
    }

    /**
     * 修改用户
     *
     * @param userUpdateVo 用户
     * @return
     */
    @Override
    public R updateCAuthUser(UserUpdateVo userUpdateVo) {
        userUpdateVo.setUpdateUser(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
        return userMapper.updateCAuthUser(userUpdateVo) > 0 ? R.ok("修改成功") : R.fail("操作失败");
    }

    /**
     * 删除用户
     *
     * @param id 用户主键
     * @return
     */
    @Override
    public R deleteCAuthUserById(String id) {
        return userMapper.deleteCAuthUserById(id) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }

    @Override
    public R deleteCAuthUserByIds(String[] ids) {
        return userMapper.deleteCAuthUserByIds(ids) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }
}
